<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>使用 SystemTap 监控 PHP DTrace 静态探针</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="features.dtrace.dtrace.html">« 使用 PHP 和 DTrace</a></li>
      <li style="float: right;"><a href="funcref.html">函数参考 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="features.dtrace.html">DTrace 动态跟踪</a></li>
    <li>使用 SystemTap 监控 PHP DTrace 静态探针</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="features.dtrace.systemtap" class="sect1">
  <h2 class="title">使用 SystemTap 监控 PHP DTrace 静态探针</h2>
  <p class="para">
   在某些 Linux 发行版上，可以使用 SystemTap 跟踪工具来跟踪 PHP 的静态 DTrace 探针。
   此特性在 PHP 5.4.20 和 PHP 5.5 中具备。
  </p>

  <div class="sect2" id="features.dtrace.systemtap-install">
   <h3 class="title">安装支持 SystemTap 的 PHP </h3>

   <p class="para">
    安装 SystemTap SDT 开发包。
    <div class="informalexample">
     <div class="example-contents">
<div class="shellcode"><pre class="shellcode"># yum install systemtap-sdt-devel</pre>
</div>
     </div>

    </div>
   </p>

   <p class="para">
    安装 PHP 并启用 DTrace 探针：
    <div class="informalexample">
     <div class="example-contents">
<div class="shellcode"><pre class="shellcode"># ./configure --enable-dtrace ...
# make</pre>
</div>
     </div>

    </div>
   </p>
  </div>

  <div class="sect2" id="features.dtrace.systemtap-list-probes">
   <h3 class="title">使用 SystemTap 列出 PHP 静态探针</h3>

   <p class="para">
    使用 <var class="filename">stap</var> 命令列出 PHP 静态探针：
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
# stap -l &#039;process.provider(&quot;php&quot;).mark(&quot;*&quot;)&#039; -c &#039;sapi/cli/php -i&#039;
</pre></div>
     </div>

    </div>
   </p>

   <p class="para">
    输出如下：
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__entry&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__return&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;error&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__caught&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__thrown&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__entry&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__return&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__entry&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__return&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__shutdown&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__startup&quot;)
</pre></div>
     </div>

    </div>
   </p>
  </div>

  <div class="sect2" id="features.dtrace.systemtap-examples">
   <h3 class="title">SystemTap 示例</h3>

   <p class="para">
    <div class="example" id="example-498">
     <p><strong>示例 #1 <var class="filename">all_probes.stp</var> for tracing all PHP Static Probes with SystemTap</strong></p>
     <div class="example-contents">
<div class="shellcode"><pre class="shellcode">probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__entry&quot;) {
    printf(&quot;Probe compile__file__entry\n&quot;);
    printf(&quot;  compile_file %s\n&quot;, user_string($arg1));
    printf(&quot;  compile_file_translated %s\n&quot;, user_string($arg2));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__return&quot;) {
    printf(&quot;Probe compile__file__return\n&quot;);
    printf(&quot;  compile_file %s\n&quot;, user_string($arg1));
    printf(&quot;  compile_file_translated %s\n&quot;, user_string($arg2));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;error&quot;) {
    printf(&quot;Probe error\n&quot;);
    printf(&quot;  errormsg %s\n&quot;, user_string($arg1));
    printf(&quot;  request_file %s\n&quot;, user_string($arg2));
    printf(&quot;  lineno %d\n&quot;, $arg3);
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__caught&quot;) {
    printf(&quot;Probe exception__caught\n&quot;);
    printf(&quot;  classname %s\n&quot;, user_string($arg1));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__thrown&quot;) {
    printf(&quot;Probe exception__thrown\n&quot;);
    printf(&quot;  classname %s\n&quot;, user_string($arg1));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__entry&quot;) {
    printf(&quot;Probe execute__entry\n&quot;);
    printf(&quot;  request_file %s\n&quot;, user_string($arg1));
    printf(&quot;  lineno %d\n&quot;, $arg2);
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__return&quot;) {
    printf(&quot;Probe execute__return\n&quot;);
    printf(&quot;  request_file %s\n&quot;, user_string($arg1));
    printf(&quot;  lineno %d\n&quot;, $arg2);
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__entry&quot;) {
    printf(&quot;Probe function__entry\n&quot;);
    printf(&quot;  function_name %s\n&quot;, user_string($arg1));
    printf(&quot;  request_file %s\n&quot;, user_string($arg2));
    printf(&quot;  lineno %d\n&quot;, $arg3);
    printf(&quot;  classname %s\n&quot;, user_string($arg4));
    printf(&quot;  scope %s\n&quot;, user_string($arg5));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__return&quot;) {
    printf(&quot;Probe function__return: %s\n&quot;, user_string($arg1));
    printf(&quot; function_name %s\n&quot;, user_string($arg1));
    printf(&quot;  request_file %s\n&quot;, user_string($arg2));
    printf(&quot;  lineno %d\n&quot;, $arg3);
    printf(&quot;  classname %s\n&quot;, user_string($arg4));
    printf(&quot;  scope %s\n&quot;, user_string($arg5));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__shutdown&quot;) {
    printf(&quot;Probe request__shutdown\n&quot;);
    printf(&quot;  file %s\n&quot;, user_string($arg1));
    printf(&quot;  request_uri %s\n&quot;, user_string($arg2));
    printf(&quot;  request_method %s\n&quot;, user_string($arg3));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__startup&quot;) {
    printf(&quot;Probe request__startup\n&quot;);
    printf(&quot;  file %s\n&quot;, user_string($arg1));
    printf(&quot;  request_uri %s\n&quot;, user_string($arg2));
    printf(&quot;  request_method %s\n&quot;, user_string($arg3));
}</pre>
</div>
     </div>

    </div>
   </p>
   <p class="para">
    在 PHP 脚本的执行过程中，上述脚本会跟踪所有的 PHP 核心静态探针：
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
# stap -c &#039;sapi/cli/php test.php&#039; all_probes.stp
</pre></div>
     </div>

    </div>
   </p>
  </div>
 </div></div></div></body></html>